<template>
	<div>
		<!--自定义搜索组件-->
		<basic-container>
			<el-row :span="24" :gutter="24">
				<el-col :span="4">
					<avue-cascader v-model="searchText" :placeholder="$t('wel.table.Please_select')" :dic="dic"></avue-cascader>
				</el-col>
				<el-col :span="3">
					<el-button type="primary" icon="el-icon-search" @click="search">{{$t('wel.table.search')}}</el-button>
				</el-col>
			</el-row>
		</basic-container>
		<basic-container>
			<avue-crud :option="option4" :data="data" :page.sync="page" @size-change="sizeChange" @current-change="currentChange"
				@search-change="searchChange">
				<template slot-scope="scope" slot="menu">
					<el-button style="margin-left:10px;" class="el-button el-button--primary el-button--small"
						type="button" icon="el-icon-edit" @click="showDetail(scope.row,scope.index)"></el-button>
				</template>
			</avue-crud>
		</basic-container>
		<el-dialog :title="$t('wel.table.Treatment_method')" :visible.sync="box" v-dialogdrag :class="{'avue-dialog':type==0}" width="40%">
			<span></span>
			<el-button  @click="errorSubmit">{{$t('wel.table.False_alarm')}}</el-button>
			<el-button type="primary" @click="successSubmit">{{$t('wel.table.Processed')}}</el-button>
		</el-dialog>
	</div>


</template>

<script>
	import {
		mapGetters
	} from "vuex";
	import request from '@/router/axios';
	import {
		baseUrl
	} from '@/config/env';

	export default {
		name: "wel",
		data() {
			return {
				editRow:{},
				dic:[],
				searchText: "",
				data: [],
				type: '',
				box: false,
				page: {
					currentPage: 1,
					total: 0,
					layout: "total,pager,prev, next",
					background: false,
					pageSize: 10
				},
				delval: null,
			};
		},
		computed: {
			...mapGetters(["userInfo"]),
			option4() {
				
				return {
					addBtn:false,
					delBtn:false,
					menu:true,
					editBtn:false,
					menuType: "icon",
					align: 'center',
					menuAlign: 'center',
					column: [{
							label: this.$t("wel.table.code"),
							prop: "code",
							//editDisabled:true,
						},
						{
							label: this.$t("wel.table.modelTitle"),
							prop: "info",
						},
						{
							label: this.$t("wel.table.tastStatus"),
							prop: "status",
							dicData: [{
									label:  this.$t("wel.table.Pending") ,
									value: 1
								}, {
									label: this.$t("wel.table.Processed") ,
									value: 2
								}, {
									label:this.$t("wel.table.False_alarm") ,
									value: 3
								}]

						},
						{
							label: this.$t("wel.table.alarmTime"),
							prop: "create_time",
						}

					]
				};
			}
		},
		created() {
			
			this.getList({
				'page': 1,
				'pageSize': this.page.pageSize
			});
			this.getContent();
		},
		methods: {
			errorSubmit(){
				this.editRow.status=3;
				this.submit();
			},
			successSubmit(){
				this.editRow.status=2;
				this.submit()
			},
			submit(){
				let that=this;
				request({
						headers: {
							'Content-Type': 'application/json;charset=utf-8'
						},
						method: 'post',
						url: baseUrl + 'userapi/Contacts/editContactsMessage',
						data: that.editRow
					})
					.then(function(response) {
						that.$message({
						          message: '操作成功',
						          type: 'success'
						        });
								that.box=false;
						
					})
					.catch(function(error) {
						console.log(error);
						that.$message.error('系统错误')
					});
				
			},
			showDetail(row){
				let that=this;
				console.log(row);
				if(row.status!=1){
					this.$message({
					          message: '事件已处理',
					          type: 'success'
					        });
					return;
				}
				that.editRow=row;
				that.box=true;
				
			},
			search() {
				this.getList({
					id: this.searchText[1],
					pageSize: 10,
					page: 1,
				});
			},

			searchChange(params, done) {
				if (!params) {
					this.$message.err("请输入搜索内容");
				}
				done();
				this.getList({
					'email': params['email'],
					'name': params['name'],
					'phone': params['phone'],
					'pageSize': 10,
					'page': 1
				});
			},

			sizeChange(val) {
				this.page.currentPage = 1
				this.page.pageSize = val
				this.getList()
			},

			currentChange(val) {
				this.page.currentPage = val
				this.getList({
					'page': val,
					'pageSize': this.page.pageSize
				});
			},
			delChange(val, index) {
				let that = this;
				this.box = true;
				this.delval = val;
				return;

			},
			getContent(data) {
				let that = this;
				request({
						headers: {
							'Content-Type': 'application/json;charset=utf-8'
						},
						method: 'post',
						url: baseUrl + 'userapi/Equipment/getAllContent',
						data: data
					})
					.then(function(response) {
						if (response.data.status == 0) {
							that.$message.error(response.data.info)
						} else if (response.data.status == 1) {
							that.dic.length=0;
							response.data.data.forEach(function(item,index){
								var newitem={label:item.name,value:item.name,children:[]};
								item.content.forEach(function(contentItem,contentIndex){
									newitem.children.push({label:contentItem.name,desc:contentItem.code,value:contentItem.id});
								})
								console.log(newitem);
								that.dic.push(newitem);
							})
							
						}
						
					})
					.catch(function(error) {
						console.log(error);
						that.$message.error('系统错误')
					});

			},
			

			getList(data) {
				let that = this;
				request({
						headers: {
							'Content-Type': 'application/json;charset=utf-8'
						},
						method: 'post',
						url: baseUrl + 'userapi/Contacts/getConotacts',
						data: data
					})
					.then(function(response) {
						if (response.data.status == 0) {
							that.$message.error(response.data.info)
						} else if (response.data.status == 1) {
							that.data = response.data.data.data;
							that.page.total = response.data.data.total;
							that.page.pageSize = response.data.data.per_page;
						}
					})
					.catch(function(error) {
						console.log(error);
						that.$message.error('系统错误')
					});

			}
		}
	};
</script>

<style scoped="scoped" lang="scss">
	.wel {
		&__header {
			padding: 25px 40px;
			border-bottom: 1px solid #e8e8e8;
			background-color: #fff;
			display: flex;
			justify-content: space-between;
			align-items: center;
		}

		&__info {
			display: flex;
			align-items: center;

			&-img {
				border-radius: 72px;
				display: block;
				width: 72px;
				height: 72px;

				img {
					width: 100%;
					height: 100%;
					display: block;
				}
			}

			&-content {
				position: relative;
				margin-left: 24px;
				color: rgba(0, 0, 0, 0.45);
				line-height: 22px;
			}

			&-title {
				font-size: 20px;
				line-height: 28px;
				font-weight: 500;
				color: rgba(0, 0, 0, 0.85);
				margin-bottom: 12px;
			}

			&-subtitle {
				position: relative;
				font-size: 14px;
				color: rgba(0, 0, 0, 0.45);
				line-height: 22px;
			}
		}

		&__extra {
			&-item {
				position: relative;
				padding: 0 32px;
				display: inline-block;

				&:last-child {
					&::after {
						display: none;
					}
				}

				&:after {
					background-color: #e8e8e8;
					position: absolute;
					top: 30px;
					right: 0;
					width: 1px;
					height: 40px;
					content: "";
				}
			}

			&-title {
				color: rgba(0, 0, 0, 0.45);
				font-size: 14px;
				line-height: 22px;
				margin-bottom: 4px;
			}

			&-subtitle {
				color: rgba(0, 0, 0, 0.85);
				font-size: 30px;
				line-height: 38px;
				margin: 0;

				span {
					color: rgba(0, 0, 0, 0.45);
					font-size: 20px;
				}
			}
		}
	}
</style>
